package com.uniinnovate.lanjingling.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.uniinnovate.lanjingling.service.UserService;
import com.uniinnovate.lanjingling.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.uniinnovate.lanjingling.utils.PageUtils;
import com.uniinnovate.lanjingling.utils.Query;

import com.uniinnovate.lanjingling.dao.JobDao;
import com.uniinnovate.lanjingling.entity.JobEntity;
import com.uniinnovate.lanjingling.service.JobService;


@Service("jobService")
public class JobServiceImpl extends ServiceImpl<JobDao, JobEntity> implements JobService {

    @Autowired
    private JobDao jobDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<JobEntity> page = this.page(
                new Query<JobEntity>().getPage(params),
                new QueryWrapper<JobEntity>()
        );
        return new PageUtils(page);
    }

    /**
     * 搜索职位（按照职位名字）
     *
     * @param word
     * @return
     */
    @Override
    public R searchJob(String word) {
        // 1.条件构造器
        QueryWrapper<JobEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(word), "name", word)
                .eq("is_audit", 1);
        // 2.数据库操作
        List<JobEntity> list = jobDao.selectList(queryWrapper);
//        List<JobEntity> list = list(queryWrapper);
        // 3.封装数据
        Map<String, Object> map = new HashMap<>();
        map.put("data", list);
        return R.ok(map);
    }

    @Override
    public R listJob(Long id) {
        QueryWrapper<JobEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("company_id", id)
                .eq("is_audit", 1);
        Map<String, Object> map = new HashMap<>();
        List<JobEntity> list = list(queryWrapper);
        map.put("data", list);
        return R.ok(map);
    }


}